package com.disv.service.strategy;

import cn.hutool.core.util.ObjectUtil;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 丁打来策略
 *
 * @author hyt
 * @date 2023/06/02
 */
@Service
public class DingCallBackStrategy {
    private final Map<Integer, DingCallBackService> serviceMapping = new ConcurrentHashMap<>();

    public DingCallBackStrategy(Map<String, DingCallBackService> strategyMap) {
        strategyMap.forEach((k, v) -> {
            this.serviceMapping.put(v.getBizType(), v);
        });
    }

    public DingCallBackService getResource(Integer bizMethod) {
        DingCallBackService dingCallBackService = this.serviceMapping.get(bizMethod);
        if (ObjectUtil.isEmpty(dingCallBackService)) {
            dingCallBackService = this.serviceMapping.get(0);
        }
        return dingCallBackService;
    }

}
